/**
 * @param {number} x
 * @return {number}
 */
 var reverse = function(x) {
    
    if (x == 0){
         return 0;
     }
     else {
         let y = x +'';
         
         let arr = y.split('').reverse();

        //  console.log(arr);
         for(let i = 0;i<arr.length;i++){
             if(arr[i] == 0){
                 delete arr[i];

             }
             if(arr[i] != 0){
                 break;
             }
         }
        //  console.log(arr);
         if(arr[arr.length-1]=='-'){
            let agent = arr[arr.length-1]; 
            delete arr[arr.length-1];
            arr.unshift(agent);
            // console.log(arr);
            let str = arr.join('');
            // console.log(str);
            let number = parseInt(str);
            // console.log(number);
            
            if(number<=-Math.pow(2,31)||number>=Math.pow(2,31)-1){
                return 0;
       
            }
            return number
         }
         else {
             let str = arr.join('');
             let number = parseInt(str);
             if(number<=-Math.pow(2,31)||number>=Math.pow(2,31)-1){
                return 0;
       
            }
             return number;
         }
        //  return number
     }
    //  if(true){
    //      return 1;
    //  }

};

console.log(reverse(1534236469));